const AccountBook = require('../model/AccountBook.js');	//账本

module.exports = {
	add: function(req, res){
		AccountBook.insert(req.body, (err, data)=>{
			if(!err){
				res.send('succeed')
			}
		});
	},
	edit: function(req, res){
		AccountBook.update(req.body.id, req.body, (err, data)=>{
			if(!err){
				res.send('succeed')
			}
		});
	},
	delete: function(req, res){
		AccountBook.remove(req.query.id, (err, data)=>{
			if(!err){
				res.send('succeed')
			}
		});
	},
	//记账界面数据
	getNowMonthTotal: function(req, res){
		var u_id = req.query.user_id;
		var month = req.query.month;
		AccountBook.getNowMonthData(u_id, month, (data)=>{
			res.send(data);
		});
	},
	//记账报表图形
	getPieReportFormData: function(req, res){
		var u_id = req.query.user_id;
		AccountBook.getPieReportForm(u_id, (data)=>{
			res.send(data);
		});
	},
	//资产
	getAccountTotal: function(req, res){
		var u_id = req.query.user_id;
		AccountBook.getAccountTotal(u_id, function(data){
			res.send(data);
		});
	},
	getAccountBookTotal: function(req, res){
		var u_id = req.query.user_id;
		AccountBook.getAccountBookTotal(u_id, function(data){
			res.send(data);
		});
	}
}